/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * RegisterObjectWindow.java
 *
 * Created on 20/03/2011, 19:09:52
 */
package manager.principal.fonte;

import java.awt.event.KeyEvent;
import java.util.LinkedList;
import javax.swing.JComboBox;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.table.TableRowSorter;
import manager.auxiliares.AutoComplete;
import manager.helpers.table.TableRender;
import manager.auxiliares.Configurations;
import manager.auxiliares.ImprimirTabela;
import manager.auxiliares.LabelColorThread;
import manager.auxiliares.MensagemExcessao;
import manager.helpers.table.TableCopy;
import manager.helpers.table.TableModel;
import manager.helpers.validation.TextFieldValidator;
import manager.interfaces.InterfaceRegister;
import manager.interfaces.InterfaceTable;

/**
 *
 * @author Thiago
 */
public class PainelRegistro extends javax.swing.JPanel {

    private InterfaceRegister interfaceRegister;
    private AutoComplete autoComplete;
    private TableModel tableModel;
    private TableRender tableRender;
    private TableRowSorter tableRowSorter;

    /** Creates new form RegisterObjectWindow */
    public PainelRegistro(InterfaceRegister interfaceRegister) {
        try {
            initComponents();
            this.interfaceRegister = interfaceRegister;
            configureWindow();
        } catch (Exception e) {
            MensagemExcessao.mostrarMensagem(e, "Interface de Cadastro Padrão");
        }
    }

    /**
     * Iniciar todas as funcionalidades e configurações da tela de registro
     */
    private void configureWindow() throws InterruptedException {
        autoComplete = new AutoComplete(jList1, jScrollPane1, jTextField1);
        configureTable();
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar (" + interfaceRegister.getTituloEntidade() + " )"));
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(interfaceRegister.getTituloEntidade() + " Encontrados(as)"));
        jLabel7.setIcon(interfaceRegister.getModuleIcon()); // NOI18N
        jLabel8.setText(interfaceRegister.getTituloEntidade());
        LabelColorThread labelColorThread = new LabelColorThread(jLabel8);
        Thread t = new Thread(labelColorThread);
        t.start();
        createFastSearchMenu(jPanel5);
        setSearchOption(jComboBox1);
        configureQuickOptions();
    }

    private void configureQuickOptions() {
        jButton2.setEnabled(interfaceRegister.isAdd());
        boolean isEdit = interfaceRegister.isEdit();
        jToggleButton1.setSelected(isEdit);
        jToggleButton1.setEnabled(isEdit);
        jToggleButton2.setEnabled(interfaceRegister.isRemove());
        jToggleButton3.setEnabled(interfaceRegister.isFiles());
        jButton4.setEnabled(interfaceRegister.isExport());
        boolean isPrint = interfaceRegister.isPrint();
        jToggleButton4.setSelected(isPrint);
        jToggleButton4.setEnabled(isPrint);
    }

    private void configureTable() {
        tableRender = new TableRender();
        tableModel = new TableModel(interfaceRegister.getNomeColunaTabela(), tableRender, new InterfaceTable() {

            public void tableAction(int id, int columnIndex,int rowIndex) {
                if (columnIndex < 0) {
                    if (jToggleButton1.isSelected()) {
                        interfaceRegister.editarEntidade(id);
                    } else if (jToggleButton2.isSelected()) {
                    } else if (jToggleButton3.isSelected()) {
                    }
                } else if (columnIndex > 0) {
                    if (jToggleButton4.isSelected()) {
                        interfaceRegister.imprimir(id);
                    }
                }
            }

            public boolean isEditableColumn(int columnIndex) {
                if (columnIndex == 0 || columnIndex == interfaceRegister.getColumnCount() - 1) {
                    return true;
                }
                return false;
            }
        });
        jTable1.setModel(tableModel);

        jTable1.getColumnModel().getColumn(0).setMaxWidth(30);
        jTable1.getColumnModel().getColumn(0).setMinWidth(30);
        jTable1.getColumnModel().getColumn(0).setResizable(false);
        jTable1.getColumnModel().getColumn(tableModel.getColumnCount() - 1).setMaxWidth(30);
        jTable1.getColumnModel().getColumn(tableModel.getColumnCount() - 1).setMinWidth(30);
        jTable1.getColumnModel().getColumn(tableModel.getColumnCount() - 1).setResizable(false);
        tableRowSorter = interfaceRegister.getTableSorter();

        jTable1.setRowSelectionAllowed(
                false);
    }

    private void search(String opcao, String searchWord) {
        tableModel.update(interfaceRegister.buscaTabela(opcao, searchWord));
        autoComplete.getjScrollPane().setVisible(false);
        jTable1.setDefaultRenderer(Object.class, tableRender);
        tableRowSorter.setModel(tableModel);

        jTable1.setRowSorter(tableRowSorter);
        
        if(interfaceRegister.temFiltroHabilitado()){
            jLabel9.setVisible(true);
        }else {
            jLabel9.setVisible(false);
        }
    }

    /**
     * Muda a cor do foreground de um JLabel para selecionado
     * @param jLabel
     */
    private void selectedLabelButton(JLabel jLabel) {
        jLabel.setForeground(Configurations.getAvaliableButtonsColor());
    }

    /**
     * Muda a cor do foreground de um JLabel para  não selecionado
     * @param jLabel
     */
    private void nonSelectedLabelButton(JLabel jLabel) {
        jLabel.setForeground(new java.awt.Color(0, 0, 0));
    }

    private void setSearchOption(JComboBox jComboBox) {
        jComboBox.removeAllItems();
        LinkedList<String> searchOption = interfaceRegister.getOpcoesBusca();
        for (int i = 0; i < searchOption.size(); i++) {
            jComboBox.addItem(searchOption.get(i));
        }
        
        if(!interfaceRegister.isFilter()){
            jButton3.setVisible(false);
        }
    }

    /**
     * Criar menu rápido de busca
     * @param jPanel Painel onde será adicionado o menu rápido
     */
    private void createFastSearchMenu(JPanel jPanel) {
        String[] menu = {"A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q",
            "R", "S", "T", "U", "V", "W", "Y", "X", "Z"};
        JLabel jLabel = new JLabel();

        jLabel.setText("TODOS");
        jPanel.add(jLabel);
        jLabel.setBounds(20, 5, 40, 20);
        jLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
        jLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel.setToolTipText(interfaceRegister.getTituloBuscaPadrao());
        jLabel.addMouseListener(new java.awt.event.MouseAdapter() {

            @Override
            public void mouseEntered(java.awt.event.MouseEvent evt) {
                selectedLabelButton((JLabel) evt.getComponent());
            }

            @Override
            public void mouseExited(java.awt.event.MouseEvent evt) {
                nonSelectedLabelButton((JLabel) evt.getComponent());
            }

            @Override
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                search(interfaceRegister.getTituloBuscaPadrao(), "%");
            }
        });


        int xPosition = 55;
        for (int i = 0; i < menu.length; i++) {
            jLabel = new JLabel();
            jLabel.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
            jLabel.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
            jLabel.setText(menu[i]);
            jLabel.setToolTipText(interfaceRegister.getTituloBuscaPadrao());
            jLabel.setCursor(new java.awt.Cursor(java.awt.Cursor.HAND_CURSOR));
            jPanel.add(jLabel);
            xPosition = xPosition + 23;
            jLabel.setBounds(xPosition, 5, 13, 20);
            jLabel.addMouseListener(new java.awt.event.MouseAdapter() {

                @Override
                public void mouseEntered(java.awt.event.MouseEvent evt) {
                    selectedLabelButton((JLabel) evt.getComponent());
                }

                @Override
                public void mouseExited(java.awt.event.MouseEvent evt) {
                    nonSelectedLabelButton((JLabel) evt.getComponent());
                }

                @Override
                public void mouseReleased(java.awt.event.MouseEvent evt) {
                    search(interfaceRegister.getTituloBuscaPadrao(), ((JLabel) evt.getComponent()).getText());
                }
            });
        }
    }

    private void changeSearchOption() {
        try {
            jTextField1.setToolTipText(jComboBox1.getSelectedItem().toString());
            interfaceRegister.changeOptionSearch(autoComplete, jComboBox1.getSelectedItem().toString(), jComboBox2);
        } catch (Exception exception) {
        }
    }

    private void printAvaliableLabel(boolean print, JLabel jLabel) {
        if (print) {
            selectedLabelButton(jLabel);
        } else {
            nonSelectedLabelButton(jLabel);
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        buttonGroup1 = new javax.swing.ButtonGroup();
        buttonGroup2 = new javax.swing.ButtonGroup();
        jPanel1 = new javax.swing.JPanel();
        jLabel2 = new javax.swing.JLabel();
        jTextField1 = new TextFieldValidator(-1, -1, false, true, "text", jLabel2);
        jLabel1 = new javax.swing.JLabel();
        jComboBox1 = new javax.swing.JComboBox();
        jButton1 = new javax.swing.JButton();
        jScrollPane1 = new javax.swing.JScrollPane();
        jList1 = new javax.swing.JList();
        jLabel7 = new javax.swing.JLabel();
        jComboBox2 = new javax.swing.JComboBox();
        jLabel8 = new javax.swing.JLabel();
        jButton3 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jPanel3 = new javax.swing.JPanel();
        jLabel3 = new javax.swing.JLabel();
        jButton2 = new javax.swing.JButton();
        jLabel4 = new javax.swing.JLabel();
        jSeparator1 = new javax.swing.JSeparator();
        jToggleButton2 = new javax.swing.JToggleButton();
        jLabel5 = new javax.swing.JLabel();
        jLabel6 = new javax.swing.JLabel();
        jToggleButton3 = new javax.swing.JToggleButton();
        jToggleButton1 = new javax.swing.JToggleButton();
        jPanel4 = new javax.swing.JPanel();
        jScrollPane2 = new javax.swing.JScrollPane();
        jTable1 = new javax.swing.JTable();
        jPanel5 = new javax.swing.JPanel();
        jLabel9 = new javax.swing.JLabel();
        jPanel6 = new javax.swing.JPanel();
        jLabel10 = new javax.swing.JLabel();
        jButton4 = new javax.swing.JButton();
        jLabel11 = new javax.swing.JLabel();
        jSeparator2 = new javax.swing.JSeparator();
        jToggleButton4 = new javax.swing.JToggleButton();

        setBackground(Configurations.getBackGroundColor());

        jPanel1.setBackground(Configurations.getBackGroundColor());
        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder("Buscar ( )"));
        jPanel1.setLayout(null);

        jLabel2.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel2.setText("Buscar");
        jPanel1.add(jLabel2);
        jLabel2.setBounds(240, 20, 210, 14);

        jTextField1.setToolTipText("");
        jTextField1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTextField1KeyReleased(evt);
            }
        });
        jPanel1.add(jTextField1);
        jTextField1.setBounds(240, 40, 405, 20);

        jLabel1.setFont(new java.awt.Font("Tahoma", 1, 11)); // NOI18N
        jLabel1.setText("Buscar por :");
        jPanel1.add(jLabel1);
        jLabel1.setBounds(10, 20, 70, 14);

        jComboBox1.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jComboBox1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jComboBox1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jComboBox1ItemStateChanged(evt);
            }
        });
        jPanel1.add(jComboBox1);
        jComboBox1.setBounds(10, 40, 220, 20);

        jButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/search.png"))); // NOI18N
        jButton1.setText("OK");
        jButton1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton1ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton1);
        jButton1.setBounds(650, 38, 67, 23);

        jList1.setCursor(new java.awt.Cursor(java.awt.Cursor.DEFAULT_CURSOR));
        jList1.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseReleased(java.awt.event.MouseEvent evt) {
                jList1MouseReleased(evt);
            }
        });
        jList1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jList1KeyReleased(evt);
            }
        });
        jScrollPane1.setViewportView(jList1);

        jPanel1.add(jScrollPane1);
        jScrollPane1.setBounds(240, 60, 405, 50);
        jScrollPane1.setVisible(false);

        jLabel7.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jPanel1.add(jLabel7);
        jLabel7.setBounds(10, 70, 40, 40);

        jComboBox2.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
        jPanel1.add(jComboBox2);
        jComboBox2.setBounds(240, 40, 405, 20);
        jComboBox2.setVisible(false);

        jLabel8.setFont(new java.awt.Font("Tahoma", 1, 18)); // NOI18N
        jLabel8.setForeground(new java.awt.Color(255, 0, 0));
        jLabel8.setHorizontalAlignment(javax.swing.SwingConstants.LEFT);
        jLabel8.setText("Label Name");
        jPanel1.add(jLabel8);
        jLabel8.setBounds(50, 70, 290, 40);

        jButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/add_filter.png"))); // NOI18N
        jButton3.setToolTipText("Filtro");
        jButton3.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton3ActionPerformed(evt);
            }
        });
        jPanel1.add(jButton3);
        jButton3.setBounds(720, 38, 30, 23);

        jPanel2.setBackground(Configurations.getBackGroundColor());
        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder("Encontrados"));

        jPanel3.setBackground(Configurations.getBackGroundColor());
        jPanel3.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel3.setLayout(null);

        jLabel3.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel3.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel3.setText("Adicionar");
        jLabel3.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel3.add(jLabel3);
        jLabel3.setBounds(0, 10, 55, 11);

        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/add_big.png"))); // NOI18N
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });
        jPanel3.add(jButton2);
        jButton2.setBounds(7, 25, 40, 40);

        jLabel4.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel4.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel4.setText("Arquivos");
        jLabel4.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel3.add(jLabel4);
        jLabel4.setBounds(0, 215, 55, 11);
        jPanel3.add(jSeparator1);
        jSeparator1.setBounds(0, 75, 60, 2);

        buttonGroup1.add(jToggleButton2);
        jToggleButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/remove_big.png"))); // NOI18N
        jToggleButton2.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton2.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jToggleButton2ItemStateChanged(evt);
            }
        });
        jPanel3.add(jToggleButton2);
        jToggleButton2.setBounds(7, 165, 40, 40);

        jLabel5.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel5.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel5.setText("Editar");
        jLabel5.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel3.add(jLabel5);
        jLabel5.setBounds(0, 85, 55, 11);

        jLabel6.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel6.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel6.setText("Remover");
        jLabel6.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel3.add(jLabel6);
        jLabel6.setBounds(0, 150, 55, 11);

        buttonGroup1.add(jToggleButton3);
        jToggleButton3.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/document_big.png"))); // NOI18N
        jToggleButton3.setVerticalTextPosition(javax.swing.SwingConstants.BOTTOM);
        jToggleButton3.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jToggleButton3ItemStateChanged(evt);
            }
        });
        jPanel3.add(jToggleButton3);
        jToggleButton3.setBounds(7, 230, 40, 40);

        buttonGroup1.add(jToggleButton1);
        jToggleButton1.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/edit_big.png"))); // NOI18N
        jToggleButton1.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jToggleButton1ItemStateChanged(evt);
            }
        });
        jPanel3.add(jToggleButton1);
        jToggleButton1.setBounds(7, 100, 40, 40);

        jPanel4.setBackground(Configurations.getBackGroundColor());

        jScrollPane2.setBackground(Configurations.getBackGroundColor());
        jScrollPane2.setBorder(javax.swing.BorderFactory.createTitledBorder(""));

        jTable1.setModel(new javax.swing.table.DefaultTableModel(
            new Object [][] {

            },
            new String [] {

            }
        ));
        jTable1.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyReleased(java.awt.event.KeyEvent evt) {
                jTable1KeyReleased(evt);
            }
        });
        jScrollPane2.setViewportView(jTable1);

        jPanel5.setBackground(Configurations.getBackGroundColor());
        jPanel5.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel5.setLayout(null);

        jLabel9.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/filter.png"))); // NOI18N
        jPanel5.add(jLabel9);
        jLabel9.setBounds(3, 4, 20, 20);
        jLabel9.setVisible(false);

        javax.swing.GroupLayout jPanel4Layout = new javax.swing.GroupLayout(jPanel4);
        jPanel4.setLayout(jPanel4Layout);
        jPanel4Layout.setHorizontalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel5, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
            .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 621, Short.MAX_VALUE)
        );
        jPanel4Layout.setVerticalGroup(
            jPanel4Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel4Layout.createSequentialGroup()
                .addComponent(jPanel5, javax.swing.GroupLayout.PREFERRED_SIZE, 30, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jScrollPane2, javax.swing.GroupLayout.DEFAULT_SIZE, 254, Short.MAX_VALUE))
        );

        jPanel6.setBackground(Configurations.getBackGroundColor());
        jPanel6.setBorder(javax.swing.BorderFactory.createTitledBorder(""));
        jPanel6.setLayout(null);

        jLabel10.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel10.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel10.setText("Imprimir");
        jLabel10.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel6.add(jLabel10);
        jLabel10.setBounds(0, 85, 55, 11);

        jButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/export_big.png"))); // NOI18N
        jButton4.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton4ActionPerformed(evt);
            }
        });
        jPanel6.add(jButton4);
        jButton4.setBounds(7, 25, 40, 40);

        jLabel11.setFont(new java.awt.Font("Tahoma", 1, 9)); // NOI18N
        jLabel11.setHorizontalAlignment(javax.swing.SwingConstants.CENTER);
        jLabel11.setText("Exportar");
        jLabel11.setHorizontalTextPosition(javax.swing.SwingConstants.CENTER);
        jPanel6.add(jLabel11);
        jLabel11.setBounds(0, 10, 55, 11);
        jPanel6.add(jSeparator2);
        jSeparator2.setBounds(0, 75, 60, 2);

        buttonGroup2.add(jToggleButton4);
        jToggleButton4.setIcon(new javax.swing.ImageIcon(getClass().getResource("/manager/images/print_big.png"))); // NOI18N
        jToggleButton4.addItemListener(new java.awt.event.ItemListener() {
            public void itemStateChanged(java.awt.event.ItemEvent evt) {
                jToggleButton4ItemStateChanged(evt);
            }
        });
        jPanel6.add(jToggleButton4);
        jToggleButton4.setBounds(7, 100, 40, 40);

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addComponent(jPanel3, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel6, javax.swing.GroupLayout.PREFERRED_SIZE, 54, javax.swing.GroupLayout.PREFERRED_SIZE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel6, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
            .addComponent(jPanel4, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel3, javax.swing.GroupLayout.DEFAULT_SIZE, 290, Short.MAX_VALUE)
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(this);
        this.setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, 753, Short.MAX_VALUE)
            .addComponent(jPanel2, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, 120, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );
    }// </editor-fold>//GEN-END:initComponents

    private void jTextField1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTextField1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            search(jComboBox1.getSelectedItem().toString(), jTextField1.getText());
        } else if (evt.getKeyCode() == KeyEvent.VK_DOWN) {
            if (autoComplete.getjScrollPane().isVisible()) {
                autoComplete.getjList().setSelectedIndex(0);
                autoComplete.getjList().requestFocus();
            }
        } else {
            if (!autoComplete.getSearchWord().equals(jTextField1.getText())) {
                autoComplete.setSearchWord(jTextField1.getText());
                autoComplete.update(interfaceRegister.buscaAutoCompletar(jComboBox1.getSelectedItem().toString(), jTextField1.getText()));
            }
        }
    }//GEN-LAST:event_jTextField1KeyReleased

    private void jToggleButton1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jToggleButton1ItemStateChanged
        printAvaliableLabel(jToggleButton1.isSelected(), jLabel5);
    }//GEN-LAST:event_jToggleButton1ItemStateChanged

    private void jToggleButton2ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jToggleButton2ItemStateChanged
        printAvaliableLabel(jToggleButton2.isSelected(), jLabel6);
    }//GEN-LAST:event_jToggleButton2ItemStateChanged

    private void jToggleButton3ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jToggleButton3ItemStateChanged
        printAvaliableLabel(jToggleButton3.isSelected(), jLabel4);
    }//GEN-LAST:event_jToggleButton3ItemStateChanged

    private void jComboBox1ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jComboBox1ItemStateChanged
        changeSearchOption();
    }//GEN-LAST:event_jComboBox1ItemStateChanged

    private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
        String searchWord = "";
        if (jComboBox2.isVisible()) {
            searchWord = jComboBox2.getSelectedItem().toString();
        } else {
            searchWord = autoComplete.getSearchWord();
        }
        search(jComboBox1.getSelectedItem().toString(), searchWord);
    }//GEN-LAST:event_jButton1ActionPerformed

    private void jList1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jList1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_ENTER) {
            autoComplete.setSearchWord(autoComplete.getjList().getSelectedValue().toString());
            search(jComboBox1.getSelectedItem().toString(), autoComplete.getSearchWord());
        }
    }//GEN-LAST:event_jList1KeyReleased

    private void jList1MouseReleased(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_jList1MouseReleased
        autoComplete.setSearchWord(autoComplete.getjList().getSelectedValue().toString());
        search(jComboBox1.getSelectedItem().toString(), autoComplete.getSearchWord());
    }//GEN-LAST:event_jList1MouseReleased

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        interfaceRegister.inserirEntidade();
    }//GEN-LAST:event_jButton2ActionPerformed

    private void jTable1KeyReleased(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jTable1KeyReleased
        if (evt.getKeyCode() == KeyEvent.VK_C) {
            if (evt.isControlDown()) {
                TableCopy.copy(jTable1);
            }
        }
}//GEN-LAST:event_jTable1KeyReleased

    private void jToggleButton4ItemStateChanged(java.awt.event.ItemEvent evt) {//GEN-FIRST:event_jToggleButton4ItemStateChanged
        printAvaliableLabel(jToggleButton4.isSelected(), jLabel10);
    }//GEN-LAST:event_jToggleButton4ItemStateChanged

    private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
        interfaceRegister.filtro();
    }//GEN-LAST:event_jButton3ActionPerformed

    private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
        ImprimirTabela imprimirTabela = new ImprimirTabela();
        imprimirTabela.imprimirTabela(tableModel, "Insumos", "Tabela de Insumos");
    }//GEN-LAST:event_jButton4ActionPerformed

    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private javax.swing.ButtonGroup buttonGroup2;
    private javax.swing.JButton jButton1;
    private javax.swing.JButton jButton2;
    private javax.swing.JButton jButton3;
    private javax.swing.JButton jButton4;
    private javax.swing.JComboBox jComboBox1;
    private javax.swing.JComboBox jComboBox2;
    private javax.swing.JLabel jLabel1;
    private javax.swing.JLabel jLabel10;
    private javax.swing.JLabel jLabel11;
    private javax.swing.JLabel jLabel2;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JLabel jLabel4;
    private javax.swing.JLabel jLabel5;
    private javax.swing.JLabel jLabel6;
    private javax.swing.JLabel jLabel7;
    private javax.swing.JLabel jLabel8;
    private javax.swing.JLabel jLabel9;
    private javax.swing.JList jList1;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JPanel jPanel3;
    private javax.swing.JPanel jPanel4;
    private javax.swing.JPanel jPanel5;
    private javax.swing.JPanel jPanel6;
    private javax.swing.JScrollPane jScrollPane1;
    private javax.swing.JScrollPane jScrollPane2;
    private javax.swing.JSeparator jSeparator1;
    private javax.swing.JSeparator jSeparator2;
    private javax.swing.JTable jTable1;
    private javax.swing.JTextField jTextField1;
    private javax.swing.JToggleButton jToggleButton1;
    private javax.swing.JToggleButton jToggleButton2;
    private javax.swing.JToggleButton jToggleButton3;
    private javax.swing.JToggleButton jToggleButton4;
    // End of variables declaration//GEN-END:variables
}
